const koa = require('koa')
const axios = require('axios')
const Router = require('@koa/router')
const { bodyParser } = require('@koa/bodyparser')
const router = new Router()
const app = new koa()
const cors = require('@koa/cors')
app.use(cors())

app.use(bodyParser())



router.get('/chat', async (ctx) => {
    // const { message } = ctx.request.body
    // console.log(message);
    message = "你好，我是吴晓慧，跟我打个招呼吧！"


    // 通过ollama调用模型
    const res = await axios.post('http://localhost:11434/api/chat', {
        model: 'deepseek-r1:7b',
        messages: [{
            role: 'user',
            content: message
        }],
        stream: false
    })

    // 解析响应
    console.log(res.data.message.content);



})
app.use(router.routes())

app.listen(3000, () => {
    console.log('server is running on port 3000')
})

